package com.thb.utils;

import java.io.IOException;

public class Base64Utils {

	/**
	 * 编码
	 * 
	 * @param bstr
	 * @return String
	 */
	@SuppressWarnings("restriction")
	public static String encode(byte[] bstr) {
		return new sun.misc.BASE64Encoder().encode(bstr);
	}

	/**
	 * 解码
	 * 
	 * @param str
	 * @return string
	 */
	@SuppressWarnings("restriction")
	public static String decode(String str) {
		byte[] bt = null;
		try {
			sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
			bt = decoder.decodeBuffer(str);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return byteToString(bt);
	}

	private static String byteToString(byte[] bytes) {
		return new String(bytes);
	}
	
	public static void main(String[] args) {
		String s = "{\"pid\":\"0fd9fd67-b16e-4bf2-befc-7128b1757e7a\"}";
		byte[] b = s.getBytes();
		System.out.println(encode(b));
	}

}

